<?php

namespace app\Http\Controllers\API;

use Auth;
use App\User;
use App\Game;
use App\Comment;
use App\GameRecord;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;

class CommentController extends Controller
{
    public function query()
    {
        $game_id = request('game_id');
        $limit = request('limit');
        $comments = Comment::where('game_id', $game_id)->orderBy('created_at', 'desc')->take($limit)->get();
        return response()->json($comments);
    }

    public function send()
    {
        $game_id = request('game_id');
        $star = request('star');
        $content = request('content');
        $user = Auth::user();
        $user_id = $user->id;
        $user_name= $user->name;
        $comment = Comment::create([
            'game_id' => $game_id,
            'user_id' => $user_id,
            'content' => $content,
            'user_name' => $user_name,
            'star' => $star,
        ]);
        return response()->json(['code' => 0, 'comment' => $comment]);
    }
}
